<template>
  <div class="page-home">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(img, imgIndx) in banners" :key="imgIndx">
        <img class="w-100" :src="img.image" alt />
      </swiper-slide>
      <div class="swiper-pagination pagination-home text-right px-3 pb-1" slot="pagination"></div>
    </swiper>
    <div class="nav-icons bg-white mt-3 text-center pt-3 text-dark-1">
      <div class="d-flex flex-wrap">
        <div class="nav-item mb-3" v-for="n in 10" :key="n">
          <i class="sprite sprite-news"></i>
          <div class="py-2">爆料站</div>
        </div>
      </div>
      <div class="bg-light py-2 fs-sm">
        <i class="sprite sprite-arrow mr-1"></i>
        <span>收起</span>
      </div>
    </div>

    <wu-list-card leftIcon="icon-menu1" title="新闻资讯" :categories="newsCats">
      <template #items="{category}">
        <router-link
          :to="`/articles/${item._id}`"
          tag="div"
          class="d-flex fs-lg py-2"
          v-for="(item, index) in category.newsList"
          :key="index"
        >
          <span class="text-info">[{{item.categoryName}}]</span>
          <span class="px-1">|</span>
          <span class="flex-1 text-dark-1 text-ellipsis">{{item.title}}</span>
          <span class="text-grey-1 ml-2 fs-sm">05/01</span>
        </router-link>
      </template>
    </wu-list-card>

    <m-list-card icon="menu1" title="英雄列表" :categories="heroCats">
      <template #items="{category}">
        <div class="d-flex flex-wrap w-100 hero-list">
          <router-link
            style="width: 20%;"
            v-for="(hero, heroIndex) in category.heroList"
            :key="heroIndex"
            tag="div"
            :to="`/heroes/${hero._id}`"
            class="d-flex flex-column p-2 ai-center jc-center"
          >
            <img :src="hero.avatar" class="w-100" />
            <span class="pt-2 fs-md">{{hero.name}}</span>
          </router-link>
        </div>
      </template>
    </m-list-card>
    <m-card icon="menu1" title="图文攻略"></m-card>
  </div>
</template>

<script>
import wuListCard from "@/components/wu-list-card";
import dayjs from "dayjs";
export default {
  components: {
    wuListCard
  },
  filters: {
    date(val) {
      return dayjs(val).format("MM/DD");
    }
  },
  data() {
    return {
      swiperOption: {
        pagination: {
          el: ".pagination-home"
        }
      },
      newsCats: [],
      heroCats: [],
      banners: []
    };
  },
  methods: {
    async initHeroCats() {
      const heroies = await this.$http.get("heroes/init");
    },
    async fetchNewsCats() {
      const res = await this.$http.get("news/list");
      this.newsCats = res.data;
    },
    async fetchHeroCats() {
      const res = await this.$http.get("heroes/list");
      this.heroCats = res.data;
    },
    async fetchAdvertiseCats() {
      const res = await this.$http.get("advertise/list");
      this.banners = res.data.items;
    }
  },
  created() {
    // this.initHeroCats()
    this.fetchAdvertiseCats();
    this.fetchNewsCats();
    this.fetchHeroCats();
  }
};
</script>

<style lang="scss">
@import "~@/assets/scss/variables.scss";
.pagination-home {
  .swiper-pagination-bullet {
    opacity: 1;
    border-radius: 0.1538rem;
    background: map-get($colors, "white");
    &.swiper-pagination-bullet-active {
      background: map-get($colors, "info");
    }
  }
}
.nav-icons {
  border-top: 1px solid $border-color;
  border-bottom: 1px solid $border-color;
  .nav-item {
    width: 25%;
    border-right: 1px solid $border-color;
    &:nth-child(4n) {
      border-right: none;
    }
  }
}
.hero-list {
  div {
    padding-top: 0;
    &:nth-child(5n) {
      padding-right: 0;
    }
    &:nth-child(5n + 1) {
      padding-left: 0;
    }
  }
}
</style>